package com.atom.test.view

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.*

class MainActivity : AppCompatActivity(), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(createContentView())
    }

    private fun createContentView(): View {
        val contentView = FrameLayout(this)
        val scrollView = ScrollView(this)
        scrollView.layoutParams = FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT
        )
        val linearLayout = LinearLayout(this)
        linearLayout.orientation = LinearLayout.VERTICAL
        linearLayout.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        linearLayout.post {
            buttons.forEach { entry ->
                linearLayout.addView(Button(this).also {
                    it.text = entry
                    it.setOnClickListener(MenuActivity@ this)
                })
            }
        }
        scrollView.addView(linearLayout)
        contentView.addView(scrollView)
        return contentView
    }

    private val buttons = arrayListOf(
        "CodeView",
        "Banner",
        "Zoom-ImageView",
        "Zoom-Layout",
    )

    override fun onClick(v: View?) {
        if (v is Button) {
            when (v.text) {
                "Banner" -> {
                    startActivity(Intent(this, ViewBannerActivity::class.java))
                }
                "Zoom-ImageView" -> {
                    startActivity(Intent(this, ViewZoomActivity::class.java))
                }
                "Zoom-Layout" -> {
                    startActivity(Intent(this, ViewZoomLayoutActivity::class.java))
                }
            }
        }
    }
}